// 递归
function convert(arr, origin) {
    return arr.map((parent) => {
        let children = origin.filter((child) => parent.permission_id === child.parent_id);
        if (children.length) {
            return { ...parent, children: convert(children, origin) };
        } else {
            return { ...parent };
        }
    });
}

let treeMenu = (state, getters) => {
    // 查找一级分类
    let cate_1st = state.menu.filter((item) => item.parent_id == 0);
    return treeMenu = [{
        permission_id: "0",
        menu_name: '全部菜单',
        resource_type_name: '根菜单',
        resource_type_id: 2,
        children: convert(cate_1st, state.menu),
    }]
}

let menu_list = (state, getters) => {
    // 查找一级分类
    let cate_1st = state.menu.filter((item) => item.parent_id == 0);
    return convert(cate_1st, state.menu);
}

export default {
    treeMenu,
    menu_list,
}